package bungabungaball;


import org.jbox2d.collision.shapes.CircleShape;
import org.jbox2d.collision.shapes.MassData;
import org.jbox2d.dynamics.Body;
import org.jbox2d.dynamics.FixtureDef;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.Image;

/**
 * The ball.
 *
 * @author Ingo Klose, Stephan Meyer, Sebastian Lehmann
 * @version 1.0
 *
 */
public class Ball extends GameObject {
    /**
     * The rotation
     */
    public float rotation;
    /**
     * The actual speed
     */
    public float speed;
    /**
     * Constructor
     * @param x
     * @param y
     * @param image
     */
    public Ball(int x, int y, Image image) {
        super(x,y,image);
        init();
    }

    /**
     * Constructor
     * @param x
     * @param y
     */
    public Ball(int x, int y) {
        super(x,y);
        init();
    }

    /**
     * Constructor
     * @param image
     */
    public Ball(Image image) {
        super(image);
        init();
    }

    /**
     * Constructor
     */
    public Ball() {
        super();
        init();
        
    }
    
    /**
     * Set the defaults
     */
    private void init() {
        speed = GlobalSettings.playerSpeed;
        rotation = GlobalSettings.playerRotation;
        
        shape = new CircleShape();
        shape.m_radius = 10.f / GlobalSettings.jBox2dFactor;

        fd = new FixtureDef();
        fd.shape = shape;
        fd.userData = "ball";
        fd.density = 0.f;
        fd.friction = 0.f;
        fd.restitution = 1.f;
    }
    
    /**
     * Draw the ball to its position
     * @param g
     */
    @Override
    public void draw(Graphics g) {
        g.drawImage(image, x, y);
    }
    
    /**
     * Set the body of the player
     * @param b 
     */
    @Override
    public void setBody(Body b) {
        super.setBody(b);
        
        MassData m = new MassData();
        m.mass = 0.0001f;
        body.setMassData(m);
    }
}
